<HTML><HEAD><TITLE>random_element(+Values, -X)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(tentative)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>random_element(+Values, -X)</H1>
Pick random element from range or collection
<DL>
<DT><EM>Values</EM></DT>
<DD>Specification of possible values
</DD>
<DT><EM>X</EM></DT>
<DD>Output variable
</DD>
</DL>
<H2>Description</H2>

	<P>
	Select a random value from the given specification of possible
	values.  The Values specification can be
	</P>
	<DL>
	<DT>Min..Max</DT>
	    <DD>A range of integers from Min to Max</DD>
	<DT>List</DT>
	    <DD>A list of possible values</DD>
	<DT>Array</DT>
	    <DD>An array of possible values</DD>
	</DL>
    
<H3>Modes and Determinism</H3><UL>
<LI>random_element(+, -) is semidet
</UL>
<H3>Fail Conditions</H3>
The range specification is empty or invalid
<H2>Examples</H2>
<PRE>
    ?- random_element(3 .. 7, X).
    X = 5
    Yes (0.00s cpu)

    ?- random_element([a, b, c, d], X).
    X = a
    Yes (0.00s cpu)

    ?- random_element([a, b, c, d], X).
    X = c
    Yes (0.00s cpu)

    </PRE>
<H2>See Also</H2>
<A HREF="../../kernel/arithmetic/random-1.html">random / 1</A>, <A HREF="../../kernel/arithmetic/frandom-1.html">frandom / 1</A>, <A HREF="../../lib/tentative/random_sample-3.html">random_sample / 3</A>, <A HREF="../../lib/tentative/tent_set_random-2.html">tent_set_random / 2</A>
</BODY></HTML>
